<template>
  <el-dialog
    title='查看流程'
    :close-on-click-modal="false"
    :visible.sync="visible">
    <template>
      <el-container style="height:100%;min-height:50vh;" direction="vertical">
        <vue-bpmn ref="bpmnView"
          v-on:error="handleError"
          v-on:shown="handleShown"
        ></vue-bpmn>
      </el-container>
    </template>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import vueBpmn from '@/components/bpmnComponents/bpmview.vue'
  export default {
    components: {
      vueBpmn
    },
    data () {
      return {
        visible: false,
        dataForm: {
          url: '',
          heightlighttask: []
        }
      }
    },
    methods: {
      handleError (err) {
        console.error('failed to show diagram', err)
      },
      handleShown () {
        console.log('diagram shown')
        for (let index in this.dataForm.heightlighttask) {
          console.log(this.dataForm.heightlighttask[index])
          this.$refs.bpmnView.highlight(this.dataForm.heightlighttask[index])
        }
      },
      init (id) {
        this.visible = true
        this.$http({
          url: this.$http.adornUrl('/flow/process/diagram'),
          method: 'get',
          params: this.$http.adornParams({
            'processinstanceid': id
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataForm.heightlighttask = data.data.runTaskId
            this.$refs.bpmnView.importXML(data.data.bpmnxml)
          } else {
            this.$refs.bpmnView.importXML('')
            this.$message.error(data.msg)
          }
        })
      }
    }
  }
</script>
